#include<bits/stdc++.h>
using namespace std;
int T,n,m,L,V;
int d[100005],v[100005],a[100005],p[100005],ans,p1[100005],ov[100005];
void spd(int i,int j)
{
	long long s;
	s=d[i]-p[j];
	long long sp;
	sp=v[i]*v[i]+2*a[i]*s;
	if(sp>V&&ov[i]!=-1)
	{
		ov[i]=1;
		p1[j]=1;
	}
}
int main()
{
	freopen("detect.in","r",stdin);
	freopen("detect.out","w",stdout);
	cin>>T;
	while(T--)
	{
		ans=0;
		memset(d,0,sizeof d);
		memset(v,0,sizeof v);
		memset(a,0,sizeof a);
		memset(p,0,sizeof p);
		memset(p1,0,sizeof p1);
		memset(ov,0,sizeof ov);
		cin>>n>>m>>L>>V;
		for(int i=0;i<n;i++)
		{
			cin>>d[i]>>v[i]>>a[i];

		}
		for(int i=0;i<m;i++)
		{
			cin>>p[i];
			for(int j=0;j<n;j++)
			{
				if(a[j]==0)
				{
					if(v[j]>V)
					{
						ov[j]=1;
						if(p[i]<=d[j])p[i]=1;
					}
					else ov[j]=-1;
				}
				spd(j,i);
			}
		}
		for(int i=0;i<n;i++)
		{
			if(ov[i]==1)ans++;
		}
		cout<<ans<<" ";
		int answ=0;
		for(int i=0;i<m;i++)
		{
			if(p1[i])answ++;
		}
		cout<<min(ans,answ)<<endl;
	}
	return 0;
}
